﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ValidationFramework.Configuration.Xml
{
	public class ParserRepository : IParserRepository
	{
		Dictionary<RuntimeTypeHandle, ISpecificationXmlParser> _readerDictionary;

		/// <summary>
		/// Initializes a new instance of the ParserRepository class.
		/// </summary>
		public ParserRepository()
		{
			_readerDictionary = new Dictionary<RuntimeTypeHandle, ISpecificationXmlParser>();
		}
		// --- IParserRepository Members

		public void AddParser(Type validatorType, ISpecificationXmlParser reader)
		{
			_readerDictionary.Add(validatorType.TypeHandle, reader);
		}

		public ISpecificationXmlParser GetParser(Type validatorType)
		{
			ISpecificationXmlParser parser;
			if (_readerDictionary.TryGetValue(validatorType.TypeHandle, out parser))
				return parser;
			else
				return null;
		}

		public int ParserCount
		{
			get
			{
				return _readerDictionary.Count;
			}
		}
	}
}
